package bio;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class BIOServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8080);
        System.out.println("服务端已启动，等待客户端连接...");
        while(true){
            Socket socket = serverSocket.accept();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String temp = null;
            String info = "";
            while( (temp  = bufferedReader.readLine())!= null){
                info+= temp;
            }
            OutputStream outputStream = socket.getOutputStream();
            PrintWriter printWriter = new PrintWriter(outputStream);
            printWriter.println("接收到客户端的请求：" + info);
            printWriter.flush();
            socket.shutdownOutput();
            printWriter.close();
            bufferedReader.close();

        }


    }
}
